package com.coder520.attend.controller;

import com.coder520.attend.pojo.Attend;
import com.coder520.attend.service.AttendService;
import com.coder520.attend.vo.QueryCondtion;
import com.coder520.common.page.PageQueryBean;
import com.coder520.user.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;


@Controller("attendController")
@RequestMapping("/Attend")
public class attendController {

    @Autowired
    private AttendService attendService;

    @RequestMapping("/attend")
    public String homeAttend(){

        return "attend";
    }

    //模拟打卡数据
    @RequestMapping("/sign")
    @ResponseBody
    public String signAttend(@RequestBody Attend attend) throws Exception {

        attendService.signAttend(attend);

        return"success";
    }

    //返回分页数据
    @RequestMapping("/attendList")
    @ResponseBody
    public PageQueryBean pageList( QueryCondtion condtion, HttpSession session){
        User user = (User) session.getAttribute("USER_SESSION");
        condtion.setUserId(user.getId());
        String[] rangeDate =condtion.getRangeDate().split("/");
        condtion.setStartDate(rangeDate[0]);
        condtion.setEndDate(rangeDate[1]);

        PageQueryBean pageQueryBean = attendService.findPageListByCondtion(condtion);
        return pageQueryBean;
    }
}
